package main

import (
	"fmt"
	"strings"

	"gitee.com/zhang-zejian/mycobra"
)

func main() {

	var cmdToUppercase = &mycobra.Command{
		Use:   "touppercase [string to be changed to uppercase]",
		Short: "Change any string to uppercase",
		Long:  "This command is used to change string to uppercase, should be useful to many cases. ",
		Args:  mycobra.MinimumNArgs(1),
		Run: func(cmd *mycobra.Command, args []string) {
			var ret []string
			for j := 0; j < len(args); j++ {
				temp := []rune(args[j])
				for i := 0; i < len(args[j]); i++ {
					if temp[i] > 98 && temp[i] < 123 {
						temp[i] = temp[i] - 32
					}
				}
				ret = append(ret, string(temp))

			}
			fmt.Println("ToUpperCase: " + strings.Join(ret, " "))
			//fmt.Println("The former string: " + strings.Join(args, " "))
		},
	}

	var cmdShowDifference = &mycobra.Command{
		Use:   "showdifference [string to be changed to uppercase]",
		Short: "Print two strings together",
		Long:  "Print the string changed and before changed so that you can see the difference",
		Args:  mycobra.MinimumNArgs(1),
		Run: func(cmd *mycobra.Command, args []string) {
			var ret []string
			for j := 0; j < len(args); j++ {
				temp := []rune(args[j])
				for i := 0; i < len(args[j]); i++ {
					if temp[i] > 98 && temp[i] < 123 {
						temp[i] = temp[i] - 32
					}
				}
				ret = append(ret, string(temp))

			}
			fmt.Println("ToUpperCase: " + strings.Join(ret, " "))
			fmt.Println("The former string: " + strings.Join(args, " "))
		},
	}

	//cmdShowDifference.Flags().IntVarP()

	var rootCmd = &mycobra.Command{Use: "app"}
	rootCmd.AddCommand(cmdToUppercase)
	cmdToUppercase.AddCommand(cmdShowDifference)
	rootCmd.Execute()

}
